<?php 
class WikiHelp extends CWidget
{
	private static $_viewPaths = 'mywidgets/_wikihelp.php';
	
	public $wiki;
	protected $_default_wiki_help_link = '#';
	protected $_wiki_help_links_config = array(
		'config' => '#',
		'backups' => '#',
		'backup_locations' => '#',
		'backup_schedule' => '#',
		'whm_accounts' => '#',
		'reboot' => '#',
		'restart' => '#',
		'whm_accounts_search' => '#',
		'whm_toolbox' => '#',
		'cpanel_accounts_bandwidthlimit' => '#',
		'cpanel_accounts' => '#',
		'cpanel_accounts_modify' => '#',
		'cpanel_accounts_change_password' => '#',
		'cpanel_accounts_search' => '#',
		'cpanel_accounts_suspend' => '#',
		'cpanel_accounts_unsuspend' => '#',
		'cpanel_accounts_terminate' => '#',
		'authy_2factor' => '#',
		'user_edit' => '#',
		'user_list' => '#',
		'user_role_permission' => '#',
		'user_roles' => '#',
		'whm_individual' => '#'
	);
	
	protected function _getWikiHelpLink()
	{
		return isset($this->_wiki_help_links_config[$this->wiki])? $this->_wiki_help_links_config[$this->wiki] : $this->_default_wiki_help_link;
	}
	
	protected static $_individual_option_wikihelp = 'UNGIVEN';
	protected function _toRender()
	{
		if(self::$_individual_option_wikihelp == 'UNGIVEN'){
			$user = app()->user->getData();
			if(empty($user->IndividualOption)){
				self::$_individual_option_wikihelp = true;
			}else{
				self::$_individual_option_wikihelp = ($user->IndividualOption->wiki_help == 1);
			}
		}
		
		return self::$_individual_option_wikihelp;
	}
	
	public function run()
	{
		if($this->_toRender()){
			$wiki_help_link = $this->_getWikiHelpLink();
			$this->renderFile(self::$_viewPaths, array(
				'wiki_help_link' => $wiki_help_link
			));
		}
	}
} 